package cn.jiyun.function.service.impl;

import cn.jiyun.function.mapper.CarMapper;
import cn.jiyun.function.mapper.DriverMapper;
import cn.jiyun.function.service.DriverService;
import cn.jiyun.pojo.function.Car;
import cn.jiyun.pojo.function.Count;
import cn.jiyun.pojo.function.Driver;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class DriverServiceImpl implements DriverService {
    @Autowired
    private DriverMapper driverMapper;
    @Autowired
    private CarMapper carMapper;

    @Override
    public PageInfo<Driver> findPage(Integer pageNum, Integer pageSize, Driver driver) {
        Page<Driver> page = PageHelper.startPage(pageNum, pageSize);
        List<Driver> list = driverMapper.findPage(page, driver);
        return new PageInfo<>(list);
    }

    @Override
    public PageInfo<Driver> findPage1(Integer pageNum, Integer pageSize) {
        Page<Driver> page = PageHelper.startPage(pageNum, pageSize);
        List<Driver> list = driverMapper.findPage1(page);
        return new PageInfo<>(list);
    }

    @Override
    public Driver findById(Integer userId) {
        Driver byId = driverMapper.findById(userId);
        List<Car> carList = carMapper.findList();
        carList.forEach(car -> {
            if (byId.getUserId().equals(car.getDid())) {
                byId.setVehicleType(car.getVehicleType());
                byId.setLicencePlate(car.getLicencePlate());
                byId.setVehicleModel(car.getVehicleModel());
                byId.setEnergyType(car.getEnergyType());
                byId.setBrand(car.getBrand());
                byId.setVender(car.getVender());
                byId.setVehicleAge(car.getVehicleAge());
                byId.setVin(car.getVin());
                byId.setDeviceNumber(car.getDeviceNumber());
            }
        });
        return byId;
    }

    @Override
    public List<Count> findCount(Count count) {
        return driverMapper.findCount(count);
    }

    @Override
    public List<Count> findCount1(Count count) {
        return driverMapper.findCount1(count);
    }

    @Override
    public void updateVerificationStatus(Integer userId, Integer status) {
        String verifier = "管理员";
        LocalDateTime approvalTime = LocalDateTime.now();
        driverMapper.updateVerificationStatus(userId, status, verifier, approvalTime);
    }


}
